package com.shop.shop_end.exception;
import com.shop.shop_end.utils.result.Result;
import com.shop.shop_end.utils.result.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局的异常处理器
//@ControllerAdvice 是 Spring 框架提供的一个注解，用于定义全局的异常处理器和全局数据绑定。
@ControllerAdvice
public class GlobalException {
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result serviceException(ServiceException e){
        return ResultUtil.error(e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result globalException(ServiceException e){
        return ResultUtil.error("系统错误");
    }
}
